#include "botsocket.h"
#include <iostream>
#include <boost/regex.hpp>

BotSocket::BotSocket(ISocketHandler &h, Data *handler) : AgentSocket(h, handler)
{
        if (handler)
                m_handler = handler->getBot();
}

BotSocket::~BotSocket()
{

}

//Send message from rtmon to end user throw bot class

void BotSocket::OnLine(const std::string &msg)
{
        if (m_handler && !msg.empty())
        {
                boost::regex const string_matcher("^hst[[:print:]]*");
                if (boost::regex_match(msg, string_matcher))
                {
                        std :: string hst(msg);
                        this->replace(hst," ", "\n");
                        const std::string hosts = "online hosts is: " + hst.substr(3, hst.length());
                        m_handler->setAvailableHosts(hosts);
                }
                else m_handler->SendMsg(msg);
        }
        Send("nil\n\n");
}